home *** CD-ROM | disk | FTP | other *** search
/ Wayzata's Best of Shareware PC/Windows 1 / Wayzata's Best of Shareware for PC-Windows - Release 1 - Wayzata Technology (1993).iso / mac / DOS / TELECOMM / PCCP047 / MESSIN.C < prev    next >
Text File  |  1992-08-14  |  4KB  |  183 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  *    MicroSoft QuickC
  3.  */
  4.  
  5. #include<stdio.h>
  6. #include<bios.h>
  7. #include<dos.h>
  8. #include<fcntl.h>
  9. #include<sys\types.h>
  10. #include<sys\stat.h>
  11. #include<signal.h>
  12. #include<process.h>
  13. #include<time.h>
  14. #include"port.h"
  15.  
  16. sendchar(c)
  17.     unsigned char c;
  18.     {
  19.     while(!((inp(basereg+STATREG)&TXMTMASK)&&(inp(basereg+MSTATREG)&CTSMASK)))
  20.         if(kbhit())
  21.             getch();
  22.     outp(basereg, c);
  23.     }
  24.  
  25. int follow;
  26.  
  27. quit()
  28.     {
  29.     cleanup(0);
  30.     exit(99);
  31.     }
  32.  
  33. sendstr(str)
  34.     char *str;
  35.     {
  36.     int i;
  37.     for(i=0;str[i]!='\0';++i)
  38.         if(str[i]=='\n')
  39.             {
  40.             sendchar('\r');
  41.             sendchar('\n');
  42.             }
  43.         else
  44.             sendchar(str[i]);
  45.     }
  46.  
  47. portgets(str)
  48.     char *str;
  49.     {
  50.     int i;
  51.     i=0;
  52.     while(i<255)
  53.         {
  54.         while(follow==index)
  55.             {
  56.             if(!(inp(basereg+MSTATREG)&DCDMASK))
  57.                 return(-1);
  58.             if(kbhit())
  59.                 getch();
  60.             }
  61.         str[i]=buf[follow++];
  62.         follow%=TBUFSIZ;
  63.         if(str[i]=='\b')
  64.             if(i>0)
  65.                 {
  66.                 i-=2;
  67.                 sendchar('\b');
  68.                 sendchar(' ');
  69.                 sendchar('\b');
  70.                 }
  71.             else
  72.                 {
  73.                 i--;
  74.                 sendchar(0x07);
  75.                 }
  76.         else
  77.             sendchar(str[i]);
  78.         if((str[i]=='\r')||(str[i]=='\n'))
  79.             {
  80.             sendchar('\r');
  81.             sendchar('\n');
  82.             str[i]='\0';
  83.             break;
  84.             }
  85.         i++;
  86.         }
  87.     str[255]='\0';
  88.     return(0);
  89.     }
  90.         
  91. main(argc, argv)
  92.     int argc;
  93.     char **argv;
  94.     {
  95.     FILE *fd;
  96.     long timestamp;
  97.     struct tm *tstructptr;
  98.     int i, j, outfd, ok, c, run, result, maxlines;
  99.     char str[256];
  100.     index=follow=0;
  101.     printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  102.     if(!strcmp(getenv("REMOTE"), "YES"))
  103.         {
  104.         printf("You appear to be already logged in remotely, judging by the environment\n");
  105.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  106.         printf("Are you sure you want to run MESSIN? (y or n) --> ");
  107.         if(getchar()!='y') /* Note getchar() and not getch()! */
  108.             {
  109.             printf("I didn't think so!\n");
  110.             exit(99);
  111.             }
  112.         else
  113.             printf("OK, you're the boss!");
  114.         }
  115.     printf("Control-C to Exit.\n");
  116.     if(argc!=6)
  117.         {
  118.         printf("USAGE: messin <comnum> <bps> <file> <max file bytes> <max message lines>\n");
  119.         exit(10);
  120.         }
  121.     comnum=atoi(argv[1])-1;
  122.     speed=atoi(argv[2]);
  123.     databits='8';
  124.     parity='n';
  125.     stopbits='1';
  126.     setport();
  127.     readset();
  128.     setup();
  129.     signal(SIGINT, quit);
  130.     if((fd=fopen(argv[3], "a"))==NULL)
  131.         {
  132.         sprintf(str, "Sorry, can't open the file.\n");
  133.         sendstr(str);
  134.         printf("Error opening MESSIN file.\n");
  135.         exit(11);
  136.         }
  137.     if(filelength(fd)>atol(argv[4]))
  138.         {
  139.         sprintf(str, "Sorry, the file has reached its limit.\n");
  140.         sendstr(str);
  141.         exit(12);
  142.         }
  143.     maxlines=atoi(argv[5]);
  144.     sprintf(str, "\nEnter your name: --> ");
  145.     sendstr(str);
  146.     timestamp=time(NULL);
  147.     tstructptr=localtime(×tamp);
  148.     if(portgets(str)==-1)
  149.         {
  150.         printf("Lost carrier detect.\n");
  151.         exit(13);
  152.         }
  153.     fprintf(fd, "\nFROM: %s\nDATE: %02d.%02d.%02d/%02d:%02d\n", str,
  154.         tstructptr->tm_year,
  155.         (tstructptr->tm_mon)+1,
  156.         tstructptr->tm_mday,
  157.         tstructptr->tm_hour,
  158.         tstructptr->tm_min);
  159.     printf("Message comming in from %s:\n", str);
  160.     sprintf(str, "End message with a line containing only period (.).\n\n");
  161.     sendstr(str);
  162.     i=0;
  163.     while(portgets(str)!=-1)
  164.         {
  165.         if((strlen(str)==1)&&(str[0]=='.'))
  166.             exit(0);
  167.         printf("%s\n", str);
  168.         fprintf(fd, "%s\n", str);
  169.         if(i==(maxlines-5))
  170.             {
  171.             sprintf(str, "*** %d LINES REMAIN BEFORE LIMIT IS REACHED ***\n", maxlines-i);
  172.             sendstr(str);
  173.             }
  174.         if(i>=maxlines)
  175.             {
  176.             sprintf(str, "*** LENGTH LIMIT REACHED ***\n");
  177.             sendstr(str);
  178.             exit(14);
  179.             }
  180.         }
  181.     exit(0);
  182.     }
  183.